Page({
  data: {
    activeIndex: 3,
    failIndex: 0,
    drawId:null,
    draw:{},  //画稿信息
    imageUrl:"",
    items: [],
  },
  onLoad(param) {
     
    this.setData({
      drawId:param.drawId
    })
  },
  onShow(){
    
    let token = my.getStorageSync({ key: 'token' }).data;
    if(token == null){
      my.confirm({
      title: '温馨提示',
      content: '当前还未登录：是否需要登录？',
      confirmButtonText: '马上登录',
      cancelButtonText: '暂不需要',
      success: (result) => {
        if(result.confirm){
            //登录
            my.redirectTo({
             url: '/pages/common/login/login'
            })
        }else{
          //暂不登录
           my.switchTab({
             url: '/pages/index/index'
            })
        }
        },
      });
      return false;
    }
    this.getDeatilOne(this.data.drawId,token);
     
  },
  getDeatilOne(drawId,token){

      let that = this;
      my.showLoading({
        content: '加载中...'
      });
        //请求数据
      my.request({
      url: 'https://tiyi.site/seaHorse/app/drawAuth/getDrawDetailAndCashDetail/'+drawId,
      method: 'GET',
      headers: 
      {
       'content-type': 'application/json',
       'token':token
      },
      data: {},
      dataType: 'json',
      success: function(res) {
        if(res.data.code == 0){
          var draw = res.data.draw;
            if(draw.state == 0 ){
              draw.stateName ="未收款"
            }else if(draw.state == 1){
              draw.stateName ="部分收款"
            }else if(draw.state == 2){
              draw.stateName ="收完款"
            }else{
              draw.stateName ="追加款"
            };
          that.setData({
            'draw.drawName':draw.drawName,
            'draw.source':draw.source,
            'draw.orderDate':draw.dateStr,
            'draw.stateName':draw.stateName,
            'draw.drawAmount':draw.drawAmount,
            'draw.leaveAmount':draw.leaveAmount,
            'draw.consumeDays':draw.consumeDays,
            'draw.state':draw.state,
            'draw.deposit':draw.deposit,
            'draw.assistCash':draw.assistCash,
            imageUrl:draw.picUrl,
            items:res.data.list
          })
        }else if(res.data.code == 401){
           //去登录
            my.redirectTo({
              url: '/pages/common/login/login'
            }) 
        }
      },
      fail: function(res) {
        my.alert({content: res});
      },
      complete: function(res) {
        my.hideLoading();
      }
      });

  },
  onTap(e){
     my.previewImage({
      urls: [
        e.target.dataset.name
      ],
    });
  }
});
